/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recursiontests.floodfill;

/**
 *
 * @author Jaybles
 */
public class FloodFill {

    enum Compass {

        NORTH(-1, 0), NORTHEAST(-1, 1), EAST(0, 1), SOUTHEAST(1, 1), SOUTH(1, 0), SOUTHWEST(1, -1), WEST(0, -1), NORTHWEST(-1, -1);
        private int y, x;

        Compass(int y, int x) {
            this.y = y;
            this.x = x;
        }

        public int getx(int x) {
            return x + this.x;
        }

        public int gety(int y) {
            return y + this.y;
        }

        public boolean checkOutOfBounds(int y, int x, int ylength, int xlength) {
            if ((y + this.y) < 0 || (y + this.y) >= ylength || (x + this.x) < 0 || (x + this.x) >= xlength) {
                return false;
            }
            else {
                return true;
            }
        }
    }

    public static void checkSquare(boolean[][] ba, int y, int x) {
        if (!ba[y][x]) {
            ba[y][x] = true;
            for (Compass i : Compass.values()) {
                if (i.checkOutOfBounds(y, x, ba.length, ba[0].length) && !ba[i.gety(y)][i.getx(x)]) {
                    checkSquare(ba, i.gety(y), i.getx(x));
                }
            }
        }
    }

    public static String gridToString(boolean[][] arr) {
        String gridToString = "";
        gridToString += printSeparator(arr.length) + "\n|";
        int count = 0;
        for (boolean[] i : arr) {
            for (boolean j : i) {
                gridToString += (j) ? "  X  |" : "     |";
            }
            gridToString += "\n"+ printSeparator(arr.length);
            if (count != i.length - 1) {
                gridToString += "\n|";
            }
            count++;
        }
       gridToString += "\n";
       return gridToString;
    }

    public static String printSeparator(int length) {
        String separator = "";
        for (int f = 0; f < length * 6; f++) {
            separator += "-";
        }
        return separator;
    }
}
